<template>
	<view class='box '>
		<!-- <uni-title type="h4" title="" ></uni-title> -->
		<!-- <uni-swipe-action>
			<uni-swipe-action-item :left-options="options2" :right-options="options2" :show="isOpened"
				:auto-close="false" @change="change" @click="bindClick">
				<view class="headTit">
					<view class="deleteTit" @click="setOpened">全部刪除</view>
				</view>
			</uni-swipe-action-item>
		</uni-swipe-action> -->
		<view class="headline">全部通知</view>

		<view class="boxCont" style="padding-top: 0;" v-if="list.length != 0">
			<view class="content-box" v-for="item in list" :key="item.id" @click="goPage(item)">
				<uni-title type="h3" :title="item.title"></uni-title>
				<view class="detailTit line-clamp2">
					{{item.content}}
					
				</view>
				<view class="time">{{setTime(item.createTime)}}</view>
			</view>
			<uni-load-more :status="status" :icon-size="14" :content-text="contentText" />
		</view>

		<!-- 空数据 -->
		<xw-empty :isShow="emptyShow" text="暂无相关消息" textColor="#777777"></xw-empty>
	</view>
</template>

<script>
	import xwEmpty from '@/pageA/uni_modules/xw-empty/xw-empty.vue';
	import {getTime} from "@/utils/auth.js"

	export default {
		componentes: {
			xwEmpty
		},
		data() {
			return {
				emptyShow: true, //无数据占位图 true显示，false隐藏
				
				list:[],
				// 商家token
				token: '',
				contentType:"",
				
				params: {
					pageNo: 1,
					pageSize: 10,
				},
				ifBottomRefresh: false,
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中',
					contentnomore: '暂无更多~'
				},
				status: 'more',
			}
		},
		//触底加载状态
		onReachBottom() {
			if (this.status != 'noMore') {
				console.log("触底")
				this.status = 'loading';
				this.ifBottomRefresh = true
				//正式服去掉这个延时器
				this.getList()
			} else {
				this.status = "noMore"
			}
		},
		onLoad(e) {
			this.contentType = this.$reqConfig.CONTENTTYPE + ";+charset=UTF-8"
			this.token = uni.getStorageSync("merchantsToken").token
			
			
			this.getList(e.type)
		},
		methods: {
			goPage(val){
				uni.navigateTo({
					url:"./msgDetail?val="+JSON.stringify(val)
				})
			},
			setTime(time){
				return getTime(time)
			},
			
			// 获取列表数据
			getList(type) {
				if(type == 2){
					this.$axios({
						url: "us/merchantOperation/message",
						method: "post",
						header: {
							"Authorization": this.token,
							"Content-type": this.contentType
						},
						data: this.params,
					}).then((res) => {
						
						if (res.result.pages >= this.params.pageNo) {
							let list = res.result.list
							if (this.ifBottomRefresh) {
								
								this.list = this.list.concat(list)
							} else {
								
								this.list = list
							}
						}else {
							this.status = 'noMore'
						}
						if (this.params.pageNo >= res.result.pages) {
							this.status = 'noMore'
						}
						this.params.pageNo++;
						
						this.emptyShow = this.list.length == 0 ? true : false
					})
				}else{
					this.$axios({
						url: "user/info/myMessage",
						method: "post",
						data: {}
					}).then((res) => {
						this.list = res.result
						this.emptyShow = this.list.length == 0 ? true : false
					})
				}
				
				
			},
		},
	}
</script>

<style lang='scss' scoped>
	.headTit{
		display: flex;
		justify-content: space-between;
		padding: 0 20rpx;
		align-items: center;
		
		.deleteTit{
			padding: 20rpx 0 40rpx 30rpx;
			color: #18BC37;
		}
	}
	.content-box {
		border-top: 2rpx solid #eee;
		padding: 20rpx;
		max-height: 220rpx;
		    overflow: hidden;

		.detailTit {
			font-size: 28rpx;
		}

		.time {
			text-align: right;
			color: #999;
			font-size: 24rpx;
		}
	}

	/deep/.uni-list-item__content-title {
		color: $uni-color-primary;

	}

	.box {
		background-color: #fff;
		margin-top: 20rpx;
		padding-top: 20rpx;

		.themeBackColor {
			border-radius: 50%;
			padding: 5rpx;
			width: 60rpx;
			height: 60rpx;
			line-height: 60rpx;
			margin-top: 10rpx;
		}
	}
</style>
